import type { NextApiRequest, NextApiResponse } from "next";
import os from "os";

type MemoryData = {
  totalMemory: string;
  freeMemory: string;
};

function getMemoryInfo(): MemoryData {
  let memoryInfo: MemoryData = {
    freeMemory: "",
    totalMemory: "",
  };
  memoryInfo.freeMemory = JSON.stringify(os.freemem());

  return memoryInfo;
}

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse<MemoryData>
) {
  res.status(200).json(getMemoryInfo());
}
